/*     */ package com.chw.admin.contractHeader;

/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.List;

/*     */ import javax.servlet.http.Cookie;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;

/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;

import com.chw.admin.contractLine.ChwContractLine;
/*     */
/*     */ import com.chw.admin.user.SysUserController;
/*     */ import com.chw.annotation.PermissionSecurity;
/*     */ import com.chw.common.ServiceData;
/*     */ import com.chw.utils.LogUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.google.gson.Gson;
 
/*     */
/*     */ @Controller
/*     */ @RequestMapping({ "/contractHeader" })
/*     */ public class ChwContractHeaderController
/*     */ {
	/* 28 */ private static LogUtil log = LogUtil.newInstance(SysUserController.class);
	/*     */
	/*     */ @Autowired
	/*     */ private IChwHeaderService chwHeaderService;

	/*     */
	/* 38 */ @RequestMapping(value = { "/findChwHeader.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	/*     */ @ResponseBody
	/*     */ @PermissionSecurity(name = "查询", module = "合同管理", btnfunc = "chw_contract_header")
	/*     */ public ServiceData find(HttpServletRequest request, ChwContractHeader chwContractHeader,
			Integer currentPage, Integer pageSize) throws Exception {
		ServiceData ret = new ServiceData();
		/*     */
		/* 40 */ PageInfo chw = this.chwHeaderService.find(chwContractHeader, currentPage, pageSize);
		/* 41 */ ret.setCode(request, ServiceData.RetCode.Success);
		/* 42 */ ret.setBo(chw);
		/* 43 */ return ret;
	}

	/*     */
	/*     */ @RequestMapping(value = { "/getHeaderLineById.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	/*     */ @ResponseBody
	/*     */ @PermissionSecurity(name = "根据id获取头", module = "合同管理", btnfunc = "chw_contract_header")
	/*     */ public ServiceData getHeaderLineById(HttpServletRequest request, String id) throws Exception
	/*     */ {
		/* 53 */ ServiceData ret = new ServiceData();
		/*     */
		/* 55 */ ChwContrachHeaderLine chw = this.chwHeaderService.getHeaderLineById(id);
		/* 56 */ ret.setCode(request, ServiceData.RetCode.Success);
		/* 57 */ ret.setBo(chw);
		/* 58 */ return ret;
		/*     */ }

	/* 66 */ @RequestMapping(value = { "/saveChwHeader.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	/*     */ @ResponseBody
	/*     */ @PermissionSecurity(name = "新增", module = "合同管理", btnfunc = "add_header")
	/*     */ public ServiceData save(HttpServletRequest request, String param) throws Exception {
		ServiceData ret = new ServiceData();
		/* 67 */ Gson gson = new Gson();
		/* 68 */ ChwContrachHeaderLine chwContrachHeaderLine = (ChwContrachHeaderLine) gson.fromJson(param,
				ChwContrachHeaderLine.class);
		/* 69 */ ChwContractHeader chwContractHeader = chwContrachHeaderLine.getChwContractHeader();
		/*     */
		/* 71 */ List list = chwContrachHeaderLine.getChwContractLine();
		/*     */
		/* 73 */ int i = this.chwHeaderService.addHeaderLine(chwContractHeader, list);
		/* 74 */ ret.setCode(request, ServiceData.RetCode.Success);
		/* 75 */ ret.setBo(Integer.valueOf(i));
		/* 76 */ return ret;
	}
 
	/*     */ @RequestMapping(value = { "/updateChwHeader.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	/*     */ @ResponseBody
	/*     */ @PermissionSecurity(name = "修改", module = "合同管理", btnfunc = "update_header")
	/*     */ public ServiceData updateChwHeader(HttpServletRequest request, String param) throws Exception {
		/* 84 */ ServiceData ret = new ServiceData();
		/* 85 */ Gson gson = new Gson();
		/* 86 */ ChwContrachHeaderLine chwContrachHeaderLine = (ChwContrachHeaderLine) gson.fromJson(param,
				ChwContrachHeaderLine.class);
		/* 87 */ ChwContractHeader chwContractHeader = chwContrachHeaderLine.getChwContractHeader();
		/* 88 */ List list = chwContrachHeaderLine.getChwContractLine();
		/*     */
		/* 90 */ int i = this.chwHeaderService.updateHeaderLine(chwContractHeader, list);
		/* 91 */ ret.setCode(request, ServiceData.RetCode.Success);
		/* 92 */ ret.setBo(Integer.valueOf(i));
		/* 93 */ return ret;
		/*     */ }

	/* 101 */ @RequestMapping(value = { "/delChwHeader.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	/*     */ @ResponseBody
	/*     */ @PermissionSecurity(name = "删除", module = "删除合同管理", btnfunc = "del_header")
	/*     */ public ServiceData del(HttpServletRequest request, String id, HttpServletResponse response)
			throws Exception {
		ServiceData ret = new ServiceData();
		/*     */
		/* 103 */ int i = this.chwHeaderService.delHeader(id);
		/* 104 */ ret.setCode(request, ServiceData.RetCode.Success);
		/* 105 */ ret.setBo(Integer.valueOf(i));
		/*     */
		/* 111 */ return ret;
	}

	/*     */
	/*     */ public void putCookie(HttpServletResponse response, String name, String value)
	/*     */ {
		/*     */ try
		/*     */ {
			/* 117 */ Cookie cookie = new Cookie(name, encode(value));
			/* 118 */ cookie.setPath("/");
			/* 119 */ response.addCookie(cookie);
			/*     */ } catch (Exception e) {
			/* 121 */ e.printStackTrace();
			/*     */ }
		/*     */ }

	@RequestMapping(value = { "/findChwLine.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "查询", module = "合同管理", btnfunc = "chw_contract_line")
	public ServiceData findfindChwLine(HttpServletRequest request, ChwContractLine chwContractLine, Integer currentPage,
			Integer pageSize) throws Exception {
		ServiceData ret = new ServiceData();
		PageInfo chw = this.chwHeaderService.findChwLine(chwContractLine, currentPage, pageSize);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(chw);
		return ret;
	}

	/*     */ private static String encode(String value) {
		/* 126 */ String result = "";
		/* 127 */ if (value != null)/*     */ try {
				/* 129 */ result = URLEncoder.encode(value, "GBK");
				/*     */ }
			/*     */ catch (UnsupportedEncodingException ex)
			/*     */ {
				/*     */ }
		/* 134 */ return result;
		/*     */ }
	/*     */ }

/*
 * Location: E:\chenya\haha\admin java\contractHeader\ Qualified Name:
 * com.chw.admin.contractHeader.ChwContractHeaderController JD-Core Version:
 * 0.6.0
 */